package com.pen.interfece.controller.admin;

import com.pen.interfece.pojo.PageResult;
import com.pen.interfece.pojo.Result;
import com.pen.interfece.pojo.dto.AdminPageQueryDTO;
import com.pen.interfece.pojo.dto.DormitoryPageQueryDTO;
import com.pen.interfece.pojo.entity.Admin;
import com.pen.interfece.pojo.entity.Dormitory;
import com.pen.interfece.pojo.vo.StudentVO;
import com.pen.interfece.service.DormitorySerivice;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/dor")
@Slf4j
public class DormitoryController {
    @Autowired
    private DormitorySerivice dormitorySerivice;
    //新增管理员
    @PostMapping("/add")
    public Result save(@RequestBody Dormitory dormitory){
        log.info("新增宿舍：{}",dormitory);
        dormitorySerivice.save(dormitory);
        return Result.success("增加成功");
    }

    //删除管理员
    @DeleteMapping
    public Result delete(@RequestParam List<Long> ids)
    {
        log.info("宿舍批量删除：{}",ids);
        dormitorySerivice.deleteBatch(ids);
        return Result.success("删除成功");
    }
    @PutMapping
    public Result update(@RequestBody Dormitory dormitory){
        log.info("宿舍修改：{}",dormitory);
        dormitorySerivice.update(dormitory);
        return Result.success("修改成功");
    }

    @GetMapping("/page")
    public Result<PageResult> page(@RequestBody DormitoryPageQueryDTO dormitoryPageQueryDTO){
        log.info("宿舍分页查询：参数为：{}",dormitoryPageQueryDTO);
        PageResult pageResult=dormitorySerivice.pageQuery(dormitoryPageQueryDTO);
        return Result.success(pageResult);
    }

    @GetMapping("/stu")
    public Result<List<StudentVO>> selectByDormitoryId(@RequestParam Integer id){
        log.info("宿舍分页查询：参数为：{}",id);
        List<StudentVO> list=dormitorySerivice.selectByDormitoryId(id);
        return Result.success(list);
    }

}
